package com.example.finalwork06.Mapper;

import com.example.finalwork06.Entity.SectorCapitalFlows;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SectorCapitalFlowsMapper {
    @Select("SELECT * FROM ( " +
            "SELECT * FROM sector_capital_flows " +
            "ORDER BY CAST(REPLACE(REPLACE(scfflows, '+', ''), '%', '') AS DECIMAL(10,2)) DESC " +
            ") WHERE ROWNUM <= 3")
    public List<SectorCapitalFlows> selectUp();

    @Select("SELECT * FROM ( " +
            "SELECT * FROM sector_capital_flows " +
            "ORDER BY CAST(REPLACE(REPLACE(scfflows, '+', ''), '%', '') AS DECIMAL(10,2)) ASC " +
            ") WHERE ROWNUM <= 3")
    public List<SectorCapitalFlows> selectDown();

    @Insert("INSERT INTO SECTOR_CAPITAL_FLOWS(SCFNAME,SCFFLOWS) VALUES(#{scfName},#{scfFlows})")
    public void insertSectorCapitalFlows(SectorCapitalFlows sectorCapitalFlows);

    @Select("select count(*) FROM SECTOR_CAPITAL_FLOWS WHERE scfName=#{name}")
    public boolean selectByName(String name);

    @Update("UPDATE SECTOR_CAPITAL_FLOWS SET SCFFLOWS=#{flows} WHERE SCFName=#{name}")
    public void updateFlows(@Param("flows")String flows, @Param("name")String name);
}
